package com.pkk.penguin.frame.know.java.driven.components;

import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.stereotype.Service;

/**
 * @description: 基础的扫描组件
 * @author: peikunkun
 * @create: 2020-07-17 14:33
 **/
@Slf4j
public class ComponentCustomScan implements TypeFilter {

  public ComponentCustomScan() {
    log.info(this.getClass().getSimpleName() + "-" + "业务类实例化了");
  }

  /**
   * @Description: 自定义匹配扫描的类
   * @Param: metadataReader:操作当前元素的信息
   * @Param metadataReaderFactory:操作父类,超类的操作
   * @return: boolean[whether this filter matches]
   * @Author: peikunkun
   * @Date: 2020/7/17 0017 下午 3:09
   */
  @Override
  public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
    //当前类的注解信息
    final AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
    //当前类的扫描的类信息
    final ClassMetadata classMetadata = metadataReader.getClassMetadata();
    //当前类资源,当前类路径
    final Resource resource = metadataReader.getResource();
    final String className = classMetadata.getClassName();
    log.debug("当前类-->" + className);
    if ("javaBean".equalsIgnoreCase(className)) {
      return true;
    }
    return false;
  }
}
